Code is given in the comment section k-nearest-neighbors Regression | MATLAB https://www.youtube.com/watch?v=zeH2WHlBLkI&t=5s